package com.coda.controller;

import com.coda.entity.LabelInfo;
import com.coda.result.Result;
import com.coda.service.LabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/label")
@Api(tags = "标签管理")
public class LabelController {
    @Autowired
    private LabelService labelService;

    /**
     * 新增或修改标签信息
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "新增或修改标签信息")
    public Result saveOrUpdate(@RequestBody LabelInfo labelInfo){
        labelService.saveOrUpdate(labelInfo);
        return Result.ok();
    }
    /**
     * 查询标签列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询标签列表")
    public Result<List<LabelInfo>> getLabelList(){
        List<LabelInfo> labelInfos = labelService.getLabelList();
        return Result.ok(labelInfos);
    }
    /**
     * 根据id删除标签信息
     */
    @GetMapping("/deleteById")
    @ApiOperation("根据id删除标签信息")
    public Result deleteById(Long id){
        labelService.deleteById(id);
        return Result.ok();
    }
}
